package cn.zane.designPattern.behaviorPatterns.chainOfResponsibilityPatterns.desion;

import cn.zane.designPattern.behaviorPatterns.chainOfResponsibilityPatterns.desion.impl.Level1AuthLink;
import cn.zane.designPattern.behaviorPatterns.chainOfResponsibilityPatterns.desion.impl.Level2AuthLink;
import cn.zane.designPattern.behaviorPatterns.chainOfResponsibilityPatterns.desion.impl.Level3AuthLink;
import cn.zane.designPattern.behaviorPatterns.chainOfResponsibilityPatterns.oldCode.AuthService;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.util.Date;

/**
 * @author zane
 * @date 2025/01/22
 * @Description
 */
@Slf4j
public class ChainOfResponsibilityPatternsMain {

    public static void main(String[] args) throws ParseException {
        AuthLink authLink = new Level3AuthLink("1000013", "组长")
                .appendNext(new Level2AuthLink("1000012", "经理")
                        .appendNext(new Level1AuthLink("1000011", "老总")));

        log.info("测试结果：{}", JSON.toJSONString(authLink.doAuth("zane", "1000998004813441", new Date())));

        // 模拟三级负责人审批
        AuthService.auth("1000013", "1000998004813441");
        log.info("测试结果：{}", "模拟三级负责人审批，组长");
        log.info("测试结果：{}", JSON.toJSONString(authLink.doAuth("zane", "1000998004813441", new Date())));

        // 模拟二级负责人审批
        AuthService.auth("1000012", "1000998004813441");
        log.info("测试结果：{}", "模拟二级负责人审批，经理");
        log.info("测试结果：{}", JSON.toJSONString(authLink.doAuth("zane", "1000998004813441", new Date())));

        // 模拟一级负责人审批
        AuthService.auth("1000011", "1000998004813441");
        log.info("测试结果：{}", "模拟一级负责人审批，老总");
        log.info("测试结果：{}", JSON.toJSONString(authLink.doAuth("zane", "1000998004813441", new Date())));
    }
}
